package com.aruba.canvasapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;

public class PathOPView extends View {
    private Paint mPaint = new Paint();
    
    public PathOPView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint.setColor(Color.RED);
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @Override
    protected void onDraw(Canvas canvas) {
        Path path1 = new Path();
        path1.addCircle(150, 150, 100, Path.Direction.CW);

        Path path2 = new Path();
        path2.addCircle(200, 200, 100, Path.Direction.CW);

        // DIFFERENCE -- 减去Path2后Path1区域剩下的部分
        // INTERSECT --- 保留Path2 和 Path1 共同的部分
        // UNION -- 保留Path1 和 Path 2
        // XOR --- 保留Path1 和 Path2 去除共同的部分
        // REVERSE_DIFFERENCE --- 减去Path1后Path2区域剩下的部分
        path1.op(path2, Path.Op.REVERSE_DIFFERENCE);
        canvas.drawPath(path1, mPaint);
    }
}
